const util = require('./base/utils');
const sleep = require('sleep');
const puppeteer = require("puppeteer");

async function main() {
    util.tcLog("====start====")

    let browser = await puppeteer.launch({
        args: ['--no-sandbox', '--disable-setuid-sandbox',
            '--disable-gpu', '--disable-dev-shm-usage',
            '--no-first-run', '--no-zygote', '--unhandled-rejections=strict'],
        headless: true,
        slowMo: 20,
        defaultViewport: {
            width: 1466,
            height: 800
        }
    });
    sleep.sleep(3);
    let page = await browser.newPage();
    // domContentLoaded 一般表示 DOM 和 CSSOM 均准备就绪的时间点
    await page.goto("http://ones.devops.sit.xiaohongshu.com/applicationlist/rnftoasis-p-red-rspace?env=sit&namespace=shequ", {waitUntil: 'domcontentloaded'});
    await page.waitFor(3000);
    if (page.url().toString().indexOf("/login") !== -1) {
        util.tcLog("===need login======");
        await page.type('#app > div > div.login-content > div.login-box.pull-left > div:nth-child(1) > div.header-tab-content > div:nth-child(1) > div > div > div > div.login-input > div > input[type=text]', "zhaobiji@xiaohongshu.com");
        await page.waitFor(1000);
        await page.type('#app > div > div.login-content > div.login-box.pull-left > div:nth-child(1) > div.header-tab-content > div:nth-child(1) > div > div > div > div.login-input > input.password', "j84BEd52");
        await page.click('#TencentCaptcha');
        await page.waitFor(1000);
        await page.goto("http://ones.devops.sit.xiaohongshu.com/applicationlist/rnftoasis-p-red-rspace?env=sit&namespace=shequ", {waitUntil: 'domcontentloaded'});
    }
    try {
        await page.waitFor(3000);
        let oneEl = '#root > section > main > div:nth-child(4) > div > div:nth-child(3) > div > div.ant-collapse.ant-collapse-borderless.ant-collapse-icon-position-left > div:nth-child(1) > div.ant-collapse-content.ant-collapse-content-active > div > div > div > div > div > div > div > div > div > table > tbody > tr > td:nth-child(';

        for (let i = 0; i < 6; i++) {
            let strI = i.toString();

            let ele = oneEl +strI +') > span';
            util.tcLog(ele);
            let text = await page.$$eval(oneEl +strI +') > span', elements => elements.map(r => r.innerText));
            util.tcLog("=====>>"+i+"<<=====" + text.toString());
        }
    }catch (ex) {
        util.tcLog("==========>" + ex);
    }
    util.tcLog("=====ending=====");
}

main().then(r => util.writeLog(r));






